<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>string类型</h1>
<script>

    /*
    * Javascript中创建字符串的方法主要有三种：
    * */
    /*
    let s1 = "javascript";
    let s2 = new String("javascript");
    let s3 = String("javascript");
    console.info(s1);
    console.info(typeof (s1));

    console.info(s2);
    console.info(s2.toString()); //对象类型可以调用成员方法。等同于valueOf();
    console.info(typeof(s2));

    console.info(s3);
    console.info(typeof(s3));
    console.info(s1==s2);
    console.info(s2==s3);*/

    //2.转义字符和unicode
    /*
    var s1 = "I'm OK! ";
    var s2 = 'I\'m OK!';
    var s3 = "使用转义字符\\";
    console.log(s1);
    console.log(s2);
    console.log(s3);
    console.log('\u4e2d\u6587');

    var name = '张三';
    var age = 18;
    var message = `你好, ${name}, 你今年${age}岁了!`;
    console.log(message);*/


    //3.使用String API
    let s1 = "Hello,Javascript! Javascript is a script language.";
    let s2 = "apple,watermelon,grape,banana";
    let s3 = new String('Hello,javascript');
    let s4 = "   Hello,Javascript     ";

    let city = ["北京","上海","广州"];
    console.info(s1.toLowerCase());
    console.info(s1.toUpperCase());
    console.info(s1.charAt(6));
    console.info(city.join("-"));
    console.info(s1.charCodeAt(0));
    console.info(s1.indexOf('script'));
    console.info(s1.lastIndexOf('script'));
    console.info(s1.slice(0,-15)); //可以从后往前截取。
    console.info(s1.substr(0,5));
    console.info(s1.substring(0,5));
    console.info(s2.split(','));
    console.info(s3.toString());
    console.info(s3.valueOf());
    console.info(s4.trim());

</script>
</body>
</html>